import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class LoveRecycManageService {

  serviceUrls: any = {
    uploadFileUrl: '/common/upload/file', // 上传

    recycleBrandListUrl: '/recycleBrand/list', // 品牌配置列表
    saveRecycleBrandUrl: '/recycleBrand/save', // 品牌配置新增
    updateRecycleBrandUrl: '/recycleBrand/update', // 品牌配置编辑、删除

    recycleSeriesListUrl: '/recycleSeries/list', // 系列配置列表
    saveRecycleSeriesUrl: '/recycleSeries/save', // 系列配置新增
    updateRecycleSeriesUrl: '/recycleSeries/update', // 系列配置修改、删除

    recycleModelListUrl: '/recycleModel/list', // 机型配置列表
    saveRecycleModelUrl: '/recycleModel/save', // 机型配置新增
    updateRecycleModelUrl: '/recycleModel/update', // 机型配置修改、删除

    hotSearchListUrl: '/hotSearch/list', // 回收热搜列表
    hotSearchSaveUrl: '/hotSearch/save', // 回收热搜新增
    hotSearchUpdateUrl: '/hotSearch/update', // 回收热搜修改编辑
    sortUpUrl: '/hotSearch/up/', // 排序--上移
    sortDownUrl: '/hotSearch/down/', // 排序--下移
    hotModelEvalListUrl: '/recycle/model/modelEvalList', // 机型名称下拉列表

    classSelectListUrl: '/recycle/type/list', // 分类选择列表
    classSelectUpdateUrl: '/recycle/type/addOrUpdateType', // 分类选择新增、编辑
    classSelectDeleteUrl: '/recycle/type/deleteType', // 分类选择删除

    modelSelectListUrl: '/recycle/model/modelTypeList', // 机型选择列表
    modelSelectUpdateUrl: '/recycle/model/addOrUpdateModelType', // 机型选择新增、编辑
    typeModalListUrl: '/recycle/model/getModelByName', // 根据机型名或品牌名查询机型
    modelSelectDeleteUrl: '/recycle/model/deleteModelType', // 机型选择管理--删除

    giveIdouList: '/recycleActivityIdolRecord/list', // 回收赠送爱豆
  };

  constructor(public httpClient: HttpClient) { }

  // 品牌配置列表
  getRecycleBrandList(params: any) {
    return this.httpClient.post(this.serviceUrls.recycleBrandListUrl, params).toPromise();
  }

  // 品牌配置新增
  saveRecycleBrandItem(params: any) {
    return this.httpClient.post(this.serviceUrls.saveRecycleBrandUrl, params).toPromise();
  }

  // 品牌配置修改、删除
  updateRecycleBrandItem(params: any) {
    return this.httpClient.post(this.serviceUrls.updateRecycleBrandUrl, params).toPromise();
  }

  // 系列配置列表
  getRecycleSeriesList(params: any) {
    return this.httpClient.post(this.serviceUrls.recycleSeriesListUrl, params).toPromise();
  }

  // 系列配置新增
  saveRecycleSeries(params: any) {
    return this.httpClient.post(this.serviceUrls.saveRecycleSeriesUrl, params).toPromise();
  }

  // 系列配置编辑、删除
  updateRecycleSeries(params: any) {
    return this.httpClient.post(this.serviceUrls.updateRecycleSeriesUrl, params).toPromise();
  }

  // 机型配置列表
  getRecycleModelList(params: any) {
    return this.httpClient.post(this.serviceUrls.recycleModelListUrl, params).toPromise();
  }

  // 机型配置新增
  saveRecycleModelItem(params: any) {
    return this.httpClient.post(this.serviceUrls.saveRecycleModelUrl, params).toPromise();
  }

  // 机型配置修改、删除
  updateRecycleModelItem(params: any) {
    return this.httpClient.post(this.serviceUrls.updateRecycleModelUrl, params).toPromise();
  }

  // 分类选择列表
  getClassSelectList(params: any) {
    return this.httpClient.get(this.serviceUrls.classSelectListUrl, { params }).toPromise();
  }

  // 分类选择新增、编辑
  updateClassSelectItem(params: any) {
    return this.httpClient.post(this.serviceUrls.classSelectUpdateUrl, params).toPromise();
  }

  // 分类选择删除
  deleteClassSelectItem(params: any) {
    return this.httpClient.get(this.serviceUrls.classSelectDeleteUrl, { params }).toPromise();
  }

  // 机型选择管理列表
  getModelSelectList(params: any) {
    return this.httpClient.get(this.serviceUrls.modelSelectListUrl, { params }).toPromise();
  }

  // 机型选择列表--新增编辑
  updateModelSelectItem(params: any) {
    return this.httpClient.post(this.serviceUrls.modelSelectUpdateUrl, params).toPromise();
  }

  // 根据手机品牌或型号查询机型List
  getTypeModalList(params: any) {
    return this.httpClient.get(this.serviceUrls.typeModalListUrl, { params }).toPromise();
  }

  // 机型选择管理--删除
  modelSelectDelete(params: any) {
    return this.httpClient.get(this.serviceUrls.modelSelectDeleteUrl, { params }).toPromise();
  }

  // 热搜列表
  gethotSearchList(params: any) {
    return this.httpClient.post(this.serviceUrls.hotSearchListUrl, params).toPromise();
  }

  // 热搜--新增
  saveHotSearchItem(params: any) {
    return this.httpClient.post(this.serviceUrls.hotSearchSaveUrl, params).toPromise();
  }

  // 热搜--修改编辑
  updateHotSearchItem(params: any) {
    return this.httpClient.post(this.serviceUrls.hotSearchUpdateUrl, params).toPromise();
  }

  // 热搜--上移排序
  hotSearchSortUp(id: number) {
    return this.httpClient.put(`${this.serviceUrls.sortUpUrl}${id}`, {}).toPromise();
  }
  // 热搜--下移排序
  hotSearchSortDown(id: number) {
    return this.httpClient.put(`${this.serviceUrls.sortDownUrl}${id}`, {}).toPromise();
  }

  // 机型名称下拉列表
  getHotmodelEvalList(params: any) {
    return this.httpClient.get(this.serviceUrls.hotModelEvalListUrl, { params }).toPromise();
  }

  // 回收赠送爱豆记录
  recycleGiveIdouList(params: any) {
    return this.httpClient.post(this.serviceUrls.giveIdouList, params).toPromise();
  }

  /**
   * 文件上传
   * @param fileToUpload
   * @returns
   */
  uploadFileData(fileToUpload: File) {
    const formData: FormData = new FormData();
    formData.append('file', fileToUpload);
    formData.append('name', "love-recyc");
    return this.httpClient.post(this.serviceUrls.uploadFileUrl, formData).toPromise();
  }
}



